package com.zl.id.controller;

import java.util.List;

import com.jfinal.kit.HttpKit;
import com.jfinal.kit.JsonKit;
import com.jfinal.kit.StrKit;
import com.zl.id.common.base.BaseController;
import com.zl.id.dao.model.Zhiw;

/**
 * 职位发布
 * 
 * @author Leon.Zhang
 *
 */
public class ZwmanageController extends BaseController {
	/**
	 * 查询职位
	 */
	public void queryAllZwList() {
		List<Zhiw> zhiwList = Zhiw.dao.find(" select * from zhiw ");
		renderJsonResult(zhiwList);
	}

	/**
	 * 查询我发布的职位
	 */
	public void querySelfZwList() {
		String userid = getPara("userid");
		List<Zhiw> zhiwList = Zhiw.dao.find(" select * from zhiw where userid = ? ", userid);
		renderJsonResult(zhiwList);
	}

	/**
	 * 查询职位
	 */
	public void queryZw() {
		String zwid = getPara("zwid");
		Zhiw zhiw = Zhiw.dao.findById(zwid);
		renderJsonResult(zhiw);
	}

	/**
	 * 新增职位
	 */
	public void addZw() {
		String jsonStr = HttpKit.readData(getRequest());
		Zhiw zhiw = JsonKit.parse(jsonStr, Zhiw.class);
		zhiw.setZwid(StrKit.getRandomUUID());
		zhiw.save();
		renderJsonSuccess();
	}

	/**
	 * 更新职位
	 */
	public void updateZw() {
		String jsonStr = HttpKit.readData(getRequest());
		Zhiw zhiw = JsonKit.parse(jsonStr, Zhiw.class);
		zhiw.update();
		renderJsonSuccess();
	}

	/**
	 * 删除职位
	 */
	public void delZw() {
		String zwid = getPara("zwid");
		Zhiw.dao.deleteById(zwid);
		renderJsonSuccess();
	}
	/**
	 * 搜索职位
	 */
	public void zwquery(){
		String jobname =this.addPer(getPara("jobname"));
		String gzlx =this.addPer(getPara("gzlx"));
		String gz =this.addPer(getPara("gz"));
		String sheng =this.addPer(getPara("sheng"));
		String shi =this.addPer(getPara("shi"));
		List<Zhiw> zhiwList = Zhiw.dao.find(
				" select * from zhiw where "
				+ " ifnull(zwms,'%') like ? "
				+ " and ifnull(gzlx,'%') like ? "
				+ " and ifnull(gz,'%') like ? "
				+ " and ifnull(sheng,'%') like ? "
				+ " and ifnull(shi,'%') like ? ",
				jobname, gzlx, gz,sheng,shi);
		renderJsonResult(zhiwList);
	}
	private String addPer(String para){
		if(para==null){
			para= "";
		}
		return para+"%";
	}

}
